Fragment
open class Fragment : ComponentCallbacks, View.OnCreateContextMenuListener, LifecycleOwner, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, SavedStateRegistryOwner, ActivityResultCaller(source)
Static library support version of the framework's android.app.Fragment. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework android.app.Fragment documentation for a class overview.
The main differences when using this support version instead of the framework version are:
- Your activity must extend FragmentActivity
- You must call getSupportFragmentManager to get the FragmentManager
Inheritors
Constructors
Link copied to clipboard
constructor()
Constructor used by the default FragmentFactory.
Alternate constructor that can be called from your default, no argument constructor to provide a default layout that will be inflated by onCreateView.
Types
Link copied to clipboard
Thrown by instantiate when there is an instantiation failure.
Link copied to clipboard
State information that has been retrieved from a fragment instance through FragmentManager.saveFragmentInstanceState.
Functions
Link copied to clipboard
Return the FragmentActivity this fragment is currently associated with.
Link copied to clipboard
Returns whether the the exit transition and enter transition overlap or not.
Link copied to clipboard
Returns whether the the return transition and reenter transition overlap or not.
Link copied to clipboard
Return the arguments supplied when the fragment was instantiated, if any.
Link copied to clipboard
Return a private FragmentManager for placing and managing Fragments inside of this Fragment.
Link copied to clipboard
Return the Context this fragment is currently associated with.
Link copied to clipboard
The Fragment's arguments when this is first called will be used as the defaults to any androidx.lifecycle.SavedStateHandle passed to a view model created using this extra.
Link copied to clipboard
Link copied to clipboard
Returns the Transition that will be used to move Views into the initial scene.
Link copied to clipboard
Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.
Link copied to clipboard
Return the FragmentManager for interacting with fragments associated with this fragment's activity.
Link copied to clipboard
Returns the cached LayoutInflater used to inflate Views of this Fragment.
Override onGetLayoutInflater when you need to change the LayoutInflater or call getLayoutInflater when you want to retrieve the current LayoutInflater.
Link copied to clipboard
Overriding this method is no longer supported and this method will be made
final
in a future version of Fragment.Link copied to clipboard
Return the LoaderManager for this fragment.
Link copied to clipboard
Returns the parent Fragment containing this Fragment.
Link copied to clipboard
Return the FragmentManager for interacting with fragments associated with this fragment's activity.
Link copied to clipboard
Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack.
Link copied to clipboard
Return
requireActivity().getResources()
.Link copied to clipboard
Returns
true
if this fragment instance's state will be retained across configuration changes, and false
if it will not.Link copied to clipboard
Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.
Link copied to clipboard
Link copied to clipboard
Returns the Transition that will be used for shared elements transferred into the content Scene.
Link copied to clipboard
Return the Transition that will be used for shared elements transferred back during a pop of the back stack.
Link copied to clipboard
Return a localized string from the application's package's default string table.
Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in java.util.Formatter and format.
Link copied to clipboard
Return the target fragment set by setTargetFragment.
Link copied to clipboard
Return the target request code set by setTargetFragment.
Link copied to clipboard
Link copied to clipboard
Get the root view for the fragment's layout (the one returned by onCreateView), if provided.
Link copied to clipboard
Get a LifecycleOwner that represents the Fragment's View lifecycle.
Link copied to clipboard
Retrieve a LiveData which allows you to observe the lifecycle of the Fragment's View.
Link copied to clipboard
Returns the ViewModelStore associated with this Fragment Overriding this method is no longer supported and this method will be made
final
in a future version of Fragment.Link copied to clipboard
Link copied to clipboard
Like instantiate but with a null argument Bundle.
open fun instantiate(@NonNull context: Context, @NonNull fname: String, @Nullable args: Bundle): Fragment
Create a new instance of a Fragment with the given class name.
Link copied to clipboard
Return true if the fragment has been explicitly detached from the UI.
Link copied to clipboard
Return true if the layout is included as part of an activity view hierarchy via the tag.
Link copied to clipboard
Link copied to clipboard
Return true if this fragment is currently being removed from its activity.
Link copied to clipboard
Returns true if this fragment is added and its state has already been saved by its host.
Link copied to clipboard
Called when the fragment's activity has been created and this fragment's view hierarchy instantiated.
Link copied to clipboard
Receive the result from a previous call to startActivityForResult.
Link copied to clipboard
Called when a fragment is attached as a child of this fragment.
Link copied to clipboard
Link copied to clipboard
This hook is called whenever an item in a context menu is selected.
Link copied to clipboard
Called when a fragment loads an animation.
Link copied to clipboard
Called when a fragment loads an animator.
Link copied to clipboard
open fun onCreateContextMenu(@NonNull menu: ContextMenu, @NonNull v: View, @Nullable menuInfo: ContextMenu.ContextMenuInfo)
Called when a context menu for the
view
is about to be shown.Link copied to clipboard
Initialize the contents of the Fragment host's standard options menu.
Link copied to clipboard
open fun onCreateView(@NonNull inflater: LayoutInflater, @Nullable container: ViewGroup, @Nullable savedInstanceState: Bundle): View
Called to have the fragment instantiate its user interface view.
Link copied to clipboard
Called when the fragment is no longer in use.
Link copied to clipboard
Called when this fragment's option menu items are no longer being included in the overall options menu.
Link copied to clipboard
Called when the view previously created by onCreateView has been detached from the fragment.
Link copied to clipboard
Called when the fragment is no longer attached to its activity.
Link copied to clipboard
Returns the LayoutInflater used to inflate Views of this Fragment.
Link copied to clipboard
Called when the hidden state (as returned by isHidden of the fragment or another fragment in its hierarchy has changed.
Link copied to clipboard
open fun onInflate(@NonNull activity: Activity, @NonNull attrs: AttributeSet, @Nullable savedInstanceState: Bundle)
open fun onInflate(@NonNull context: Context, @NonNull attrs: AttributeSet, @Nullable savedInstanceState: Bundle)
Called when a fragment is being created as part of a view layout inflation, typically from setting the content view of an activity.
Link copied to clipboard
Link copied to clipboard
Called when the Fragment's activity changes from fullscreen mode to multi-window mode and visa-versa.
Link copied to clipboard
This hook is called whenever an item in your options menu is selected.
Link copied to clipboard
This hook is called whenever the options menu is being closed (either by the user canceling the menu with the back/menu button, or when an item is selected).
Link copied to clipboard
Called when the Fragment is no longer resumed.
Link copied to clipboard
Called by the system when the activity changes to and from picture-in-picture mode.
Link copied to clipboard
Prepare the Fragment host's standard options menu to be displayed.
Link copied to clipboard
Callback for when the primary navigation state of this Fragment has changed.
Link copied to clipboard
Link copied to clipboard
Called when the fragment is visible to the user and actively running.
Link copied to clipboard
Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted.
Link copied to clipboard
Called when the Fragment is visible to the user.
Link copied to clipboard
Called when the Fragment is no longer started.
Link copied to clipboard
Called immediately after onCreateView has returned, but before any saved state has been restored in to the view.
Link copied to clipboard
Called when all saved state has been restored into the view hierarchy of the fragment.
Link copied to clipboard
Postpone the entering Fragment transition until startPostponedEnterTransition or executePendingTransactions has been called.
Postpone the entering Fragment transition for a given amount of time and then call startPostponedEnterTransition.
Link copied to clipboard
fun <I, O> registerForActivityResult(@NonNull contract: ActivityResultContract<I, O>, @NonNull callback: ActivityResultCallback<O>): ActivityResultLauncher<I>
If the host of this fragment is an ActivityResultRegistryOwner the ActivityResultRegistry of the host will be used.
fun <I, O> registerForActivityResult(@NonNull contract: ActivityResultContract<I, O>, @NonNull registry: ActivityResultRegistry, @NonNull callback: ActivityResultCallback<O>): ActivityResultLauncher<I>
Link copied to clipboard
Registers a context menu to be shown for the given view (multiple views can show the context menu).
Link copied to clipboard
Requests permissions to be granted to this application.
Link copied to clipboard
Return the FragmentActivity this fragment is currently associated with.
Link copied to clipboard
Return the arguments supplied when the fragment was instantiated.
Link copied to clipboard
Return the Context this fragment is currently associated with.
Link copied to clipboard
Return the FragmentManager for interacting with fragments associated with this fragment's activity.
Link copied to clipboard
Return the host object of this fragment.
Link copied to clipboard
Returns the parent Fragment containing this Fragment.
Link copied to clipboard
Get the root view for the fragment's layout (the one returned by onCreateView).
Link copied to clipboard
Sets whether the the exit transition and enter transition overlap or not.
Link copied to clipboard
Sets whether the the return transition and reenter transition overlap or not.
Link copied to clipboard
Supply the construction arguments for this fragment.
Link copied to clipboard
When custom transitions are used with Fragments, the enter transition callback is called when this Fragment is attached or detached when not popping the back stack.
Link copied to clipboard
Sets the Transition that will be used to move Views into the initial scene.
Link copied to clipboard
When custom transitions are used with Fragments, the exit transition callback is called when this Fragment is attached or detached when popping the back stack.
Link copied to clipboard
Sets the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.
Link copied to clipboard
Report that this fragment would like to participate in populating the options menu by receiving a call to onCreateOptionsMenu and related methods.
Link copied to clipboard
Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by FragmentManager.saveFragmentInstanceState.
Link copied to clipboard
Set a hint for whether this fragment's menu should be visible.
Link copied to clipboard
Sets the Transition that will be used to move Views in to the scene when returning due to popping a back stack.
Link copied to clipboard
Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change).
Link copied to clipboard
Sets the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.
Link copied to clipboard
Sets the Transition that will be used for shared elements transferred into the content Scene.
Link copied to clipboard
Sets the Transition that will be used for shared elements transferred back during a pop of the back stack.
Link copied to clipboard
Optional target for this fragment.
Link copied to clipboard
Set a hint to the system about whether this fragment's UI is currently visible to the user.
Link copied to clipboard
Gets whether you should show UI with rationale before requesting a permission.
Link copied to clipboard
Call startActivity from the fragment's containing Activity.
Link copied to clipboard
open fun startActivityForResult(@NonNull intent: Intent, requestCode: Int, @Nullable options: Bundle)
Call startActivityForResult from the fragment's containing Activity.
Link copied to clipboard
open fun startIntentSenderForResult(@NonNull intent: IntentSender, requestCode: Int, @Nullable fillInIntent: Intent, flagsMask: Int, flagsValues: Int, extraFlags: Int, @Nullable options: Bundle)
Call startIntentSenderForResult from the fragment's containing Activity.
Link copied to clipboard
Begin postponed transitions after postponeEnterTransition was called.
Link copied to clipboard
Prevents a context menu to be shown for the given view.